<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head >
    <title>搜索管理后台 - 标签库管理</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="stylesheet" type="text/css" href="${request.contextPath}/css/style_manager.css">
	<script type="text/javascript" src="${request.contextPath}/js/jquery-1.4.2.js"></script>
	<script type="text/javascript" src="${request.contextPath}/js/manager.js"></script>
	<script type="text/javascript" src="${request.contextPath}/js/my97/WdatePicker.js"></script>
	<script type="text/javascript" src="${request.contextPath}/js/jquery.overblock-1.2.js"></script>
		
	<script type="text/javascript">
	var list = null;
	$(function(){
		list = new TagListObject('listtag', 'dataDiv', 'pageNumDiv');
		list.init();
		list.list(1, function(){
			initEvent();
		});
	});
	
	function TagListObject(url, listId, pageNumId){
		ListObject.call(this, url, listId, pageNumId);
	}
	/**
	* 通过原型方法，继承了父类的function
	*/
	TagListObject.prototype = new ListObject();
	TagListObject.prototype.success = function(json) {
		var h = '';
		if(json !== null && json.length > 4){
			var obj1 = eval(json)[0];
			this.total = obj1.count;
			var list = obj1.list;
			h = '<table id="listTable" border="0" >' +
				'	<tr>' +
				'		<td class="center title" width="45"><span id="selectAll">选择</span></td>' +
				'		<td class="title sort" onclick="sortData(\'keyWord\');">关键字</td>' +
				'		<td class="center title">类别</td>' +
				'		<td width="140" class="center title sort" onclick="sortData(\'addTime\');">添加时间</td>' +
				'		<td width="140" class="center title sort" onclick="sortData(\'updateTime\');">更新时间</td>' +
				'		<td width="70" class="center title sort">操作</td>' +
				'	</tr>';
			for(var i = 0, len = list.length; i < len; i ++){
				var o = list[i];
				var kid = o.id;
				var kw = o.keyWord || [];
				var cn = o.cate && o.cate.name || '';
				var atime = o.addTimeStr || '';
				var utime = o.updateTimeStr || '';
				
				h +='	<tr class="bgTr">' +
					'		<td class="center"><input type="checkbox" class="checkBoxes" value='+kid+' /></td>' +
					'		<td class="moreOptTd">'+kw+'</td>' +
					'		<td class="center" style="white-space:nowrap;">'+cn+'</td>' +
					'		<td class="center" style="white-space:nowrap;">'+atime+'</td>' +
					'		<td class="center" style="white-space:nowrap;">'+utime+'</td>' +
					'		<td class="center" style="white-space:nowrap;">' +
					'			<a href="javascript:void(0);" onclick="deleteData(\''+kid+'\');" class="aDelete">删除</a>' +
					'			<a href="javascript:void(0);" onclick="stopTag(\''+kid+'\');" class="aDelete">撤销</a>' +
					'		</td>' +
					'	</tr>';
			}
			if(list.length < 1){
				h += '<tr><td colspan="8">'+noDataMessage+'</td></tr>';
			}
			h += '</table>';
			$('#'+this.listId).html(h);
		}else{
			h = noDataMessage;
			alert(1);
			$('#'+this.listId).html(h);
		}
	};
	TagListObject.prototype.setParams = function() {
		this.paramObj.cp = this.cp;
		this.paramObj.pp = this.pp;
		
		this.paramObj.keyword = v('#keyword');
		this.paramObj.beginTime = v('#bdate');
		this.paramObj.endTime = v('#edate');
		this.paramObj.sort = v('#sortInput');
		this.paramObj.cateId = v('#allCateSelect');
	};

	function initEvent(){
		$('#addCate').click(function(){
			$('#addCateInfo').showPop({'blockStyle':{color:'#dddddd'}, 'closeable':false, 'fadeTime':300});
		});
		$('#closeCate').click(function(){
			$('#addCateInfo').hidePop(300);
		});
		
		$('#newTag').bind('click', function(){
			$('#tagCateSelect').html('').append($('#allCateSelect').clone());
			$('#tagWordFloat').showPop({'blockStyle':{color:'#dddddd'}, 'closeable':false, 'fadeTime':300});
			$('#tagWordInput').focus();
		});
		$('#closeTagWord').click(function(){
			$('#tagWordFloat').hidePop(300);
		});
		
		$('#tagWordInput').keyup(function(e){
			var v = $(this).val().trim();
			
			if(v != null && v.length > 0 && e.keyCode == 13){
				var tarObj = $('#newTagsDiv');
				var spanId = v;
				var sid = '#' + spanId;
				if(tarObj.find(sid).length > 0){
					tarObj.find(sid).fadeOut(300, function(){$(this).fadeIn(100);});
				}else{
					var h = '<span class="samewordspan" style="font-size:13px;" id="'+spanId+'" ><span class="samewordHtml">'+v+'</span><sup onclick="deleteNewTag(this);" class="samewordspansup" >×</sup></span>';
					tarObj.append(h);
				}
				$(this).val('').focus();
			}
		});
		
		$('#titleDiv1').click(function(){
			$('#tagWordInput').focus();
		});
	}
	
	function deleteNewTag(thisObj){
		var tar = $(thisObj).parent('.samewordspan');
		tar.fadeOut(300, function(){tar.remove();});
	}
	
	function ListData(n, func){
		list.list(n, func);
	}
	var sortType = 1;
	function sortData(f){
		var s = f || '';
		s = (sortType > 0 ? '' : '-') + s;
		sortType = sortType * -1;
		$('#sortInput').val(s);
		ListData(1)
	}
		
	function reset(){
		$('#bdate,#edate,#keyword,#sortInput').val('');
		$("#allCateSelect option:eq(0)").attr('selected', 'selected');
		ListData(1)
	}
	
	function doBatchCate(){
		var ids = getids();
		if(ids == null || ids.length < 1){
			return;
		}
		var cateid = $('#cateInfoHTML #allCateSelect').val();
		ajax('batchCateTags?ids='+ids+'&cateId='+cateid, function(rs){
			reloadPage();
		});
	}
	var msg = '删除该标签，会导致包含该标签的所有商品都将移除此标签，是否继续？';
	function deleteData(ids){
		if(confirm(msg)){
			ajax('deltags?ids=' + ids, function(rs){
				showRs('删除成功');
				ListData()
			});
		}
	}
	function stopTag(ids){
		if(confirm('只会将该标签从商品中移除，仍然保留标签自身信息，是否继续？')){
			ajax('stoptags?ids=' + ids, function(rs){
				showRs('操作成功');
				ListData()
			});
		}
	}
	
	function batchAdd(){
		var wordSpan = $('#newTagsDiv').find('.samewordspan');
		if(wordSpan.length < 1){
			alert('请输入标签内容，并按回车确认');
			return;
		}
		var words = wordSpan.map(function(){
			return $(this).find('.samewordHtml').html();
		}).get().join(' ');
		var cateId = $('#tagCateSelect').find('#allCateSelect').val();
		words = encodeURI(words);
		ajax('addtag?keyword=' + words + '&cateId=' + cateId, function(rs){
			reloadPage();
		});
	}
	</script>
	<style type="text/css">
	#table1 td{
		font-size:13px;
	}

	input.number{
		border-radius:3px;
		border:1px solid gray;
		height:22px;
		padding-left:5px;
	}
	input.btn{
		border-radius:5px;height:25px;border:1px solid #aaaaaa;
	}
	input.inputBox{
		border-radius:4px;
		border:1px solid #aaaaaa;
		height:23px;
		padding-left:5px;
	}
	.tarDivBG{
		background-color:#B3E568;
	}
	</style>
  </head>
  <body>
  	<div id="containerDiv">
  		<div style="">
			<h3>标签词库管理</h2>
  		</div>
  		<div style="font-size:13px;padding:5p;margin-bottom:20px;">
			日期：从
			<input type="text" class="inputBox" value="" readOnly="readOnly" onclick="WdatePicker({el:'bdate',dateFmt:'yyyy-MM-dd HH:mm:ss'});" id="bdate" size="16" />
			到
			<input type="text" class="inputBox" value="" readOnly="readOnly" id="edate" size="16" onclick="WdatePicker({el:'edate',dateFmt:'yyyy-MM-dd HH:mm:ss'});" />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;类别：
			<select style="border-radius:4px;height:23px;" id="allCateSelect">
				<option value="">全部</option>
			</select>
			<span id="addCate" class="addBtn">+</span>
			
			<div style="margin-top:5px;">
				关键字：&nbsp;<input type="text" class="inputBox" id="keyword" value="" size="50" />&nbsp;&nbsp;
				<input type="button" value="搜索" class="btnStyle1" onclick="ListData(1);" />&nbsp;&nbsp;
				<input type="button" value="重置" style="background-color:red;" class="btnStyle1"  onclick="reset();" />
				<input type="button" value="刷新" class="btnStyle1" onclick="reloadPage();" />
				&nbsp;&nbsp;&nbsp;&nbsp;
			  	<input type="hidden" id="sortInput" value="" />
			  	<span style="float:right;margin-right:10px;" >
				  	<input type="button" value="新增标签" class="btnStyle1" id="newTag" />
				  	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				  	<a href="tagGoods" style="color:gray;" target="_blank">商品标签管理</a>
				</span>
			</div>
  		</div>
  		<div>
  		</div>
	  	<div id="dataDiv">
	  		
	  	</div>
	  	<div id="pageNumDiv" style="padding-right:-20px;">
	  		
	  	</div>
		  	<input type="button" value="指定类别" id="batchCate" onclick="batchCate();" class="btnStyle1" />
		  	<span id="batchResult" style="color:red;font-weight:bold;margin-left:230px;">&nbsp;</span>
  	</div>
  	
	<div id="tagWordFloat" class="wordFloat" style="width:500px;height:420px;">
		<div id="titleDiv" class="titleDiv">
		  	<div id="closeTagWord" class="closeDiv" >×</div>
		  	<div style="float:left;margin-top:-5px;">添加标签</div>
		</div>
		<div style="padding:15px;">
			<div id="tagCateSelect" style="margin-bottom:15px;">
				
			</div>
			<div id="titleDiv1" style="width:450px;height:30px;margin-bottom:-37px;padding-top:7px;font-size:13px;color:#cccccc;text-align:right;">
				输入标签（<span style="color:red;">中英文和数字</span>）内容，按回车键（Enter）确认
			</div>
			<input type="text" id="tagWordInput" onkeyup="this.value=this.value.replace(/[^\u4E00-\u9FA5|^\d|^a-zA-Z]/gi, '')" class="sameImput" size="70" style="background:transparent;" />
			<div id="newTagsDiv" style="5px;margin-top:15px;width:450px;height:230px;overflow:auto;">
				
			</div>
			<div>
				<input type="button" value="添加" id="batchAdd" onclick="batchAdd();" class="btnStyle1" />
			</div>
		</div>
  	</div>
  	
  	<input type="hidden" value="添加标签词库类别" id="cateTitleInput" />
  	<input type="hidden" value="tag_word" id="CATEINFOTYPE" />
  	<#include "../cate_float.ftl" />
  </body>
</html>
